package com.ruoyi.server.api.memberUserManagement.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.exception.errorCode.CommonException;
import com.ruoyi.common.core.domain.CommonResult;
import com.ruoyi.server.api.memberCardNumber.domain.MemberCardNumber;
import com.ruoyi.server.api.memberUserManagement.model.MemberUserAndBindCardModel;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.server.api.memberUserManagement.domain.MemberUserManagement;
import com.ruoyi.server.api.memberUserManagement.service.IMemberUserManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员用户Controller
 *
 * @author zmh
 * @date 2024-06-11
 */
@RestController
@RequestMapping("/member/memberUserManagement")
public class MemberUserManagementController extends BaseController
{
    @Autowired
    private IMemberUserManagementService memberUserManagementService;

    /**
     * 查询会员用户列表
     */
    @PreAuthorize("@ss.hasPermi('member:memberUserManagement:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberUserManagement memberUserManagement)
    {
        startPage();
        List<MemberUserManagement> list = memberUserManagementService.selectMemberUserManagementList(memberUserManagement);
        return getDataTable(list);
    }
    /**
    * @Author ZMH
    * @Description 根据id查询单个用户信息列表
    * @Date 2024/6/11 11:14
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param memberUserAndTypeModel
    */
    @PutMapping ("/getById")
    public AjaxResult getById(@RequestBody MemberUserAndBindCardModel memberUserAndTypeModel){
        Integer id = memberUserAndTypeModel.getId();
        String venueUniqueIdentifier = memberUserAndTypeModel.getVenueUniqueIdentifier();
        MemberUserAndBindCardModel byId = memberUserManagementService.getById(id, venueUniqueIdentifier);
        return AjaxResult.success(byId);
    }

    /**
     * 导出会员用户列表
     */
    @PreAuthorize("@ss.hasPermi('member:memberUserManagement:export')")
    @Log(title = "会员用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberUserManagement memberUserManagement)
    {
        List<MemberUserManagement> list = memberUserManagementService.selectMemberUserManagementList(memberUserManagement);
        ExcelUtil<MemberUserManagement> util = new ExcelUtil<MemberUserManagement>(MemberUserManagement.class);
        util.exportExcel(response, list, "会员用户数据");
    }

    /**
     * 获取会员用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:memberUserManagement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(memberUserManagementService.selectMemberUserManagementById(id));
    }

    /**
     * 新增会员用户
     */
    @PreAuthorize("@ss.hasPermi('member:memberUserManagement:add')")
    @Log(title = "会员用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MemberUserAndBindCardModel memberUserAndBindCardModel) throws CommonException {
        return memberUserManagementService.insertMemberUserManagement(memberUserAndBindCardModel);
    }

    /**
     * 修改会员用户
     */
    @PreAuthorize("@ss.hasPermi('member:memberUserManagement:edit')")
    @Log(title = "会员用户", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody MemberUserAndBindCardModel memberUserAndBindCardModel)
    {
        return memberUserManagementService.updateMemberUserManagement(memberUserAndBindCardModel);
    }

    /**
     * 删除会员用户
     */
    @PreAuthorize("@ss.hasPermi('member:memberUserManagement:remove')")
    @Log(title = "会员用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(memberUserManagementService.deleteMemberUserManagementByIds(ids));
    }

    /**
    * @Author hjh
    * @Description 根据卡号获取用户信息
    * @Date 2024/6/12 21:43
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param membershipCardNumber
    */

    @Log(title = "会员用户", businessType = BusinessType.OTHER)
    @GetMapping("selectUserInfoByNumid")
    public AjaxResult selectUserInfoByNumid (String membershipCardNumber){
        return memberUserManagementService.selectUserInfoByNumid(membershipCardNumber);
    }

    /**
    * @Author hjh
    * @Description 查询当天入场人数
    * @Date 2024/6/13 10:04
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param currentDate
    */
    @Log(title = "查询当天入场人数", businessType = BusinessType.OTHER)
    @GetMapping("selectEntranceNumber")
    public AjaxResult selectEntranceNumber (String currentDate){
        return memberUserManagementService.selectEntranceNumber(currentDate);
    }

    /**
    * @Author hjh
    * @Description 查询用户是否入场
    * @Date 2024/6/13 11:28
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param membershipCardNumber
    */
    @Log(title = "查询用户是否入场", businessType = BusinessType.OTHER)
    @GetMapping("/userIfEntrance")
    public AjaxResult userIfEntrance (String membershipCardNumber){
        AjaxResult result = memberUserManagementService.userIfEntrance(membershipCardNumber);
        return result;
    }

    /**
    * @Author hjh
    * @Description 查询会员是否有私教
    * @Date 2024/6/16 20:54
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param membershipCardNumber
    */
    @Log(title = "查询会员是否有私教", businessType = BusinessType.OTHER)
    @GetMapping("selectIfPersonalTrainer")
    public AjaxResult selectIfPersonalTrainer (String membershipCardNumber){
        return memberUserManagementService.selectIfPersonalTrainer(membershipCardNumber);
    }

    /**
    * @Author hjh
    * @Description 判断会员卡是否有会员
    * @Date 2024/6/17 14:22
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param membershipCardNumber
    */
    @Log(title = "判断会员卡是否有会员", businessType = BusinessType.OTHER)
    @GetMapping("ifMemberCardBind")
    public AjaxResult ifMemberCardBind (String membershipCardNumber){
        return memberUserManagementService.ifMemberCardBind(membershipCardNumber);
    }
}
